
//package java_cup;

/**
 * This class represents a reduce actionPart within the parse table. The actionPart
 * simply stores the production that it reduces with and responds to queries
 * about its type.
 *
 * @version last updated: 11/25/95
 * @author Scott Hudson
 */
public class ReduceAction : ParseAction {

    /*-----------------------------------------------------------*/
    /*--- Constructor(s) ----------------------------------------*/
    /*-----------------------------------------------------------*/

    /**
     * Simple constructor.
     * 
     * @param prod the production this actionPart reduces with.
     */
    public ReduceAction(ProductionDraft prod) /*throws internal_error*/ {
        /* sanity check */
        if (prod == null)
            throw new InternalError("Attempt to create a reduce_action with a null production");

        _reduce_with = prod;
    }

    /*-----------------------------------------------------------*/
    /*--- (Access to) Instance Variables ------------------------*/
    /*-----------------------------------------------------------*/

    /** The production we reduce with. */
    public ProductionDraft _reduce_with;

    /** The production we reduce with. */
    public ProductionDraft ReduceWith => _reduce_with;

    /*-----------------------------------------------------------*/
    /*--- General Methods ---------------------------------------*/
    /*-----------------------------------------------------------*/

    /** Quick access to type of actionPart. */
    /*@Override*/
    public int Kind => REDUCE;

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** Equality test. */
    public bool equals(ReduceAction other) {
        return other != null && other.ReduceWith == ReduceWith;
    }

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** Generic equality test. */
    /*@Override*/
    public override bool Equals(Object? other) {
        if (other is ReduceAction)
            return equals((ReduceAction)other);
        else
            return false;
    }

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** Compute a hash code. */
    /*@Override*/
    public override int GetHashCode() {
        /* use the hash code of the production we are reducing with */
        return ReduceWith.GetHashCode();
    }

    /** Convert to string. */
    /*@Override*/
    public override string ToString() {
        return "REDUCE(with prod " + ReduceWith.Index + ")";
    }

    /*-----------------------------------------------------------*/

}
